public class NumberList {
    private NumberNode list;

    public NumberList()
    {
        list = null;
    }

    public void add(Number num)
    {
        NumberNode node = new NumberNode(num);
        NumberNode current;
        if (list == null)
        {
            list = node;
        }
        else
        {
            current = list;
            while (current.next != null)
            {
                current = current.next;
            }
            current.next = node;
        }
    }

    @Override
    public String toString()
    {
        String result = "";

        NumberNode current = list;
        while (current != null)
        {
            result += current.number + " ";
            current = current.next;
        }
        return result;
    }

    private class NumberNode
    {
        public Number number;
        public NumberNode next;

        public NumberNode(Number number)
        {
            this.number = number;
            next = null;
        }
    }

    public void sort()
    {
        NumberNode min;
        Number temp;
        NumberNode node = list;

        while (node != null)
        {
            min = node;
            NumberNode current = min.next;
            while (current!=null)
            {
                if(Integer.parseInt(String.valueOf(min.number)) > Integer.parseInt(String.valueOf(current.number)))
                {
                    min = current ;
                }
                current = current.next;
            }
            temp = min.number;
            min.number = node.number;
            node.number = temp;

            node  = node.next;
        }
    }
}

